import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"
import { RequestHeaderEnum } from "/@/enums/httpEnum"
import { Api } from "/@/api/url"

export const listSubTenant = (params) => {
  const headers = {}
  headers[RequestHeaderEnum.TENANT_ID] = params.tenantId
  return defHttp.get({ url: '/system-service/tenant/listSubTenant', params, headers })
}

export const pageTenant = (params) => {
  return defHttp.get({ url: '/system-service/tenant/pageTenant', params })
}

export const listTenant = (params) => {
  return defHttp.get({ url: '/system-service/tenant/listAll', params })
}

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdateTenant = (params, isUpdate) => {
  const url = '/system-service/tenant/' + (isUpdate ? 'update' : 'save')
  return defHttp.post({ url: url, params })
}

/**
 * 拥有者获取
 */
export const getOwnerTenant = () =>
  defHttp.get({ url: '/system-service/tenant/getOwnerTenant' })


/**
 * 拥有者更新
 */
export const updateOwnerTenant = (params) =>
  defHttp.post({ url: '/system-service/tenant/updateOwnerTenant', params })


/**
 * 查询详情
 * @param params
 */
export const getTenant = (params) =>
  defHttp.get({ url: '/iam-service/tenant/getTenant', params })


/**
 * 删除
 * @param params
 */
export const deleteTenant = (params, handleSuccess) => {
  // const aes = new AesEncryption()
  // const encryptData = aes.encryptByAES(JSON.stringify(params))
  // console.log('--------------------------------', encryptData)
  return defHttp.delete({ url: '/system-service/tenant/delete', data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

/**
 * 批量删除租户
 * @param params
 */
export const batchDeleteTenant = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: '/system-service/tenant/deleteBatch', data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

/**
 * 获取当前租户套餐菜单权限
 */
export const listCurrentPackageMenuTree = () =>
  defHttp.get({ url: '/system-service/tenantPackage/listMenuTree' })

